package com.lyeducation.redis;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


/**
 * Created by Lintuer on 2017/10/26. AOP记录用户请求信息
 */
@Aspect
@Order(1)
@Component
public class RedisReleasePoolAspect {
    private Logger logger = LoggerFactory.getLogger(getClass());
    ThreadLocal<Long> startTime = new ThreadLocal();
    @Autowired
    private RedisTemplate redisTemplate;
//RedisConnectionUtils.unbindConnection(redisTemplate.getConnectionFactory());

    @Pointcut("execution(public * com.lyeducation.redis.RedisUtil.*(..))")
    public void redisReleasePool() {
    }
//
//    @Before("redisReleasePool()")
//    public void doBefore(JoinPoint joinPoint) throws Throwable {

//    }


    @AfterReturning(pointcut = "redisReleasePool()")
    public void runAfterReturning() {
        logger.info("redisConnectionUtils.unbindConnection exe");
        RedisConnectionUtils.unbindConnection(redisTemplate.getConnectionFactory());
    }
}
